﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPFColorPickerLib;

namespace WPFTrees
{
    /// <summary>
    /// Interaction logic for ColorsDlg.xaml
    /// </summary>
    public partial class ColorsDlg : Window
    {
        public ColorsDlg()
        {
            InitializeComponent();


            Binding b = new Binding("BackgroundColor");
            b.Source = DefaultSettings.Default;
            b.Mode = BindingMode.TwoWay;
            rectBackgroundColor.SetBinding(Rectangle.FillProperty,b);

            /*Binding bWorkspace = new Binding();
            bWorkspace.Source = Workspace.Workspace.Instance.BackgroundColor;
            bWorkspace.Mode = BindingMode.OneWayToSource;
            BindingExpressionBase ex =  rectBackgroundColor.SetBinding(Rectangle.FillProperty, bWorkspace);
            MessageBox.Show(ex.ToString());
            */
            Binding b2 = new Binding("LeafLabelColor");
            b2.Source = DefaultSettings.Default;
            b2.Mode = BindingMode.TwoWay;
            rectLeafLabelColor.SetBinding(Rectangle.FillProperty, b2);
            

            Binding b3 = new Binding("LeafColor");
            b3.Source = DefaultSettings.Default;
            b3.Mode = BindingMode.TwoWay;
            rectLeafColor.SetBinding(Rectangle.FillProperty, b3);
        }

        private void btnLeafLabelColor_Click(object sender, RoutedEventArgs e)
        {
            ColorDialog dlg 
                = new ColorDialog(DefaultSettings.Default.LeafLabelColor.Color);
            if (dlg.ShowDialog() == true)
            {
                rectLeafLabelColor.Fill = new SolidColorBrush(dlg.SelectedColor);
            }
        }

        private void btnLeafColor_Click(object sender, RoutedEventArgs e)
        {
            ColorDialog dlg 
                = new ColorDialog(DefaultSettings.Default.LeafColor.Color);
            if (dlg.ShowDialog() == true)
            {
                rectLeafColor.Fill = new SolidColorBrush(dlg.SelectedColor);
            }
        }

        private void btnBackgroundColor_Click(object sender, RoutedEventArgs e)
        {
            ColorDialog dlg 
                = new ColorDialog(DefaultSettings.Default.BackgroundColor.Color);
            if (dlg.ShowDialog()==true)
            {
                rectBackgroundColor.Fill = new SolidColorBrush(dlg.SelectedColor);            
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DialogResult = true;            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
